package com.tj.collection.utils;

import com.fqgj.common.utils.StringUtils;
import org.apache.poi.util.StringUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2020/2/24
 * Time: 下午5:31
 */
public class IndiaMobileUtil {

    public static String countryCodeFilter(String mobile) {
        if (mobile == null || mobile.length() == 0) {
            return mobile;
        }
        mobile = mobile.replaceAll(" ", "");
        if (mobile.startsWith("+91")) {
            return mobile.substring(3);
        }
        if (mobile.length() > 10 && mobile.startsWith("91")) {
            return mobile.substring(2);
        }
        return mobile;
    }

    public static boolean isMobileNumber(String mobile) {
        if(StringUtils.isEmpty(mobile)){
            return false;
        }
        Pattern pattern = Pattern.compile("[0-9]{1,}");
        Matcher matcher = pattern.matcher(mobile);
        boolean result = matcher.matches();
        return result;
    }

    public static void main(String[] args) {
        System.out.println(countryCodeFilter("+917338262362"));
        System.out.println(countryCodeFilter("8095892939"));
        System.out.println(countryCodeFilter("+91 90717 73793"));
        System.out.println(countryCodeFilter("+919818718417"));
        System.out.println(countryCodeFilter("90 36 983088"));
        System.out.println(countryCodeFilter("+91 99007 20520"));
        System.out.println(countryCodeFilter("8792315879"));
        System.out.println(countryCodeFilter("91487 73996"));
        System.out.println(countryCodeFilter("91 76764 02683"));
        System.out.println(countryCodeFilter("917676402683"));
        System.out.println(countryCodeFilter("*444#"));

        System.out.println(isMobileNumber("PunoB"));
        System.out.println(isMobileNumber(countryCodeFilter("91 76764 02683")));
        System.out.println(isMobileNumber(countryCodeFilter("+919818718417")));
        System.out.println(isMobileNumber(countryCodeFilter("8095892939")));

    }

}
